package Model;


import java.sql.Statement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;/*private String id;
private String name;
private String desc;
private String details;*/







import Entity.*;
import S2.server.ConnectionManage;

public class ReportModel {
	private static Connection conn = ConnectionManage.getInstance().getConnection();

	public static Report addReport(String id, String name, String desc,String details  ) throws SQLException 
{
		String sql = "INSERT INTO Report (id,name,desc,details)"+"VALUES(?,?,?,?)";
		ResultSet rs = null;
		Report bean =  new Report();
		
		try (PreparedStatement stmt = conn.prepareStatement(sql);) {
			stmt.setString(1, id);
			stmt.setString(2, name);
			stmt.setString(3 , desc);
			stmt.setString(4, details);
		
			
			rs = stmt.executeQuery();
			
			if (rs.next()) {
				bean.setName(name);
				bean.setId(id);
				bean.setDesc(desc);
				bean.setDetails(details);
				return bean;
			} else {
				return null;
			}

		} catch (SQLException e) {
			System.err.println(e);
			return null;
		} finally {
			if (rs != null) {
				rs.close();
			}
		}
		
}
	public static Report UpdateReport(String id, String name, String desc,String details  ) throws SQLException {
		String sql = "Update INTO Reports (id,name,desc,details)"+"VALUES(?,?,?,?)";
		ResultSet rs = null;
		Report bean =  new Report();

		try (PreparedStatement stmt = conn.prepareStatement(sql);) {
			stmt.setString(1, id);
			stmt.setString(2,name);
			stmt.setString(3,desc);
			stmt.setString(4,details);
			
			rs = stmt.executeQuery();
			if (rs.next()) {
				bean.setName(name);
				bean.setId(id);
				bean.setDesc(desc);
				bean.setDetails(details);
				return bean;
			} else {
				return null;
			}
			
	}
	 catch (SQLException e) {
		System.err.println(e);
		return null;
	} finally {
		if (rs != null) {
			rs.close();
		}
	}
		
	}
	public static void DeleteReport(String id, String name) throws SQLException {

		String sql = "DELETE FROM Report " +  "WHERE id = ? AND name=? ";
		ResultSet rs = null;
		
		try (PreparedStatement stmt = conn.prepareStatement(sql);)
		{			
			stmt.setString(1, id);
			stmt.setString(2, name);
			rs = stmt.executeQuery();
		}
		 catch (SQLException e) {
				System.err.println(e);
				
			} finally {
				if (rs != null) {
					rs.close();
				}
			
		
			}
	}
	public static Report GetReport(String id, String name) throws SQLException {
		String sql = "SELECT * FROM" + " report WHERE" + " id=? AND name=? ";
		ResultSet rs = null;
		Report bean =  new Report();

		try (PreparedStatement stmt = conn.prepareStatement(sql);) {
			stmt.setString(1, id);
			stmt.setString(2, name);
			
			
			rs = stmt.executeQuery();
			
			if (rs.next()) {
				bean.setId(id);
				bean.setName(name);
				bean.setDesc(rs.getString("desc"));
				bean.setDetails(rs.getString("details"));
				return bean;
			} else {
				return null;
			}

		} catch (SQLException e) {
			System.err.println(e);
			return null;
		} finally {
			if (rs != null) {
				rs.close();
			}
		}
}
	}
